<!DOCTYPE html>
<html lang="zh_CN">
<head>
<#--引入外部文件-->
    <#include "../common/header.ftl">
</head>
<body>

<div class="container" style="margin-top: 20px">
<#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
        <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
        <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <select class="form-control" name="strategyId" id="strategies">
                <#list strategies as s>
                    <option value="${s.id}">${s.title}</option>
                </#list>
                </select>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <script>
                    $("#strategies option[value='${qo.strategyId!}']").prop("selected", true);
                </script>
                <a href="javascript:" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>分类名称</th>
                    <th>所属攻略</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th></th>
                </tr>
            <#--使用Freemark的指令完成循环迭代-->
            <#list pageInfo.list as entity>
                <tr>
                    <td>${entity_index + 1}</td>
                    <td>${entity.name}</td>
                    <td>${entity.strategy.title}</td>
                    <td>${entity.sequence}</td>
                    <td>
                        <#if entity.state==false >
                            禁用
                        <#elseif entity.state==true>
                            启用
                        </#if>
                    </td>
                    <td>
                        <a href="javascript:" class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                            <span class="glyphicon glyphicon-pencil"></span> 修改
                        </a>
                    </td>
                </tr>
            </#list>
            </table>

        <#include "../common/page.ftl">
        </div>
    </div>
</div>


<#--模态框必须是body的子元素-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <#--模态框标题-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body">
            <#--填充编辑界面-->
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">分类名称：：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name" />
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">所属攻略：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="strategy.id">
                            <#list strategies as s>
                                <option value="${s.id}">${s.title}</option>
                            </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">序号：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="sequence" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">状态：</label>
                        <div class="col-lg-6">
                            <select name="state" class="form-control">
                                <option value="false">禁用</option>
                                <option value="true" selected>启用</option>
                            </select>
                        </div>
                    </div>

                </form>

            </div>
        <#--模态框底部按钮-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".inputBtn").click(function () {
            //1:先清空模态框的数据,再来做操作
            $("#inputModal input").val("");
            //2:获取当前按钮中的自定义JSON对象
            var obj = $(this).data("json");
            //3:只有编辑按钮才做数据回显
            if (obj) {
                $("#inputModal input[name='id']").val(obj.id);
                $("#inputModal input[name='name']").val(obj.name);
                $("#inputModal select[name='strategy.id']").val(obj.strategyId);
                $("#inputModal input[name='sequence']").val(obj.sequence);
                $("#inputModal select[name='state']").val(obj.state+"");
            }
            $("#inputModal").modal('show');
        })
        /*
                   使用jQueryform修改模态框的提交方式-ajax方式
                   设置提交方式必须在设计提交表单之前
                */
        $("#editForm").ajaxForm(function(data) {
            //操作成功刷新界面
            if (data.success) {
                location.reload();
            } else {
                //操作失败,提交用户错误信息
                $.messager.alert("温馨提示", data.msg);
            }
        });

        //模态框的表单提交
        $(".submitBtn").click(function() {
            $("#editForm").submit();
        });

    })
</script>

</body>
</html>